package com.lzh.persevere.common;

import com.lzh.persevere.config.enums.request.AppHttpCodeEnum;
import com.lzh.persevere.config.enums.request.ErrorCodeEnum;

/**
 * 返回类
 *
 * @author luzhiheng
 * @since 2023-11-12
 */
public class ResultUtil {

    /**
     * 成功
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> R<T> success(T data) {
        return new R<>(200, data, "success");
    }

    /**
     * 失败
     *
     * @param errorCodeEnum
     * @return
     */
    public static R error(ErrorCodeEnum errorCodeEnum) {
        return new R<>(errorCodeEnum);
    }

    /**
     * 失败
     *
     * @param appHttpCodeEnum
     * @return
     */
    public static R error(AppHttpCodeEnum appHttpCodeEnum) {
        return new R<>(appHttpCodeEnum);
    }

    /**
     * 失败
     *
     * @param code
     * @param message
     * @return
     */
    public static R error(int code, String message) {
        return new R(code, null, message);
    }

    /**
     * 失败
     *
     * @param errorCodeEnum
     * @return
     */
    public static R error(ErrorCodeEnum errorCodeEnum, String message) {
        return new R(errorCodeEnum.getCode(), null, message);
    }

}
